package com.jeff.android.lab.architecture.arouter.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;

import com.alibaba.android.arouter.launcher.ARouter;
import com.jeff.android.lab.BaseActivity;
import com.jeff.android.lab.R;
import com.jeff.android.lab.architecture.arouter.bean.Car;
import com.jeff.android.lab.commonlib.router.Constant;
import com.jeff.android.lab.architecture.arouter.bean.UserInfo;
import com.jeff.utils.ToastUtil;

/**
 * @author: duff
 * @date: 2019/3/11
 * @since: 1.0.0
 */
@Route(path = Constant.ACTIVITY_URL_LOGIN)
public class LoginActivity extends BaseActivity {

    @Autowired(name = Constant.NAME)
    String mName;
    @Autowired(name = Constant.AGE)
    int mAge;

    @Autowired
    Car car;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        setTitle("登录");

        ARouter.getInstance().inject(this);

        handleIntent();

        Log.d("dingfeng", "params:" + mName + "  " + mAge);

        if (car != null)
            Log.d("dingfeng", "car:" + car.toString());
    }

    private void handleIntent() {
        Intent intent = getIntent();

        if (intent != null) {
            String name = intent.getStringExtra(Constant.NAME);
            int age = intent.getIntExtra(Constant.AGE, 100);
            UserInfo user = intent.getParcelableExtra(Constant.USER);

            if (user != null) {
                ToastUtil.show(this, "Name:" + name
                        + "  Age:" + age + " " +
                        user.toString());
            }
        }


    }

}
